import { asyncRoutes } from '@/router'
import Layout from '@/layout'
const constRoutes = [
  {
    path: '/',
    component: Layout,
    meta: { title: '面板' },

    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard'),
        meta: { title: '面板' }
      }

    ]
  },
  {
    path: '/login',
    component: () => import("@/views/login"),
    meta: { title: '登录' },
    hidden: true

  },


]

export default {
  namespaced: true,
  state() {
    return {
      routes: constRoutes
    }
  },
  getters: {

  },
  mutations: {
    // 5、设置给完成的路由映射变量
    setRoutes(state, newRoutes) {
      // 静态路由+动态路由
      state.routes = [...constRoutes, ...newRoutes]
    }

  },
  actions: {
    // 4、通过权限菜单标识，筛选出该用户的动态路由
    filterRoutes(context, data) {
      const userRoutes = []
      asyncRoutes.forEach(item => {
        if (data.includes(item.name)) userRoutes.push(item)
      })
      context.commit('setRoutes', userRoutes)
      return userRoutes
    }

  }
}